/**
 * Created by Administrator on 2016/5/5.
 */
var SPSdk = (function () {

    var SHARE_URL = "http://qzonestyle.gtimg.cn/qzone/hybrid/app/gamebar/fusion/dist/aio.share.js";
    var PAY_URL = "http://qzonestyle.gtimg.cn/qzone/mobilepage/gamesBar/common/pop_pay_tips.js";

    function SPSdk() {
        this.appId = "";
        this.appKey = "";
        this.token = "";
        this.payKey = "";
        this.loginKey = "";
        this.queryParams = {};
        this.userToken = "";
        this.otherKey = "";
        this.userID = "";
        this.paycallback = {};
    }

    var __proto = SPSdk.prototype;

    __proto.login = function (param, callback, shareHandler) {
        console.log("玩吧H5登录：" + JSON.stringify(param));
        var m_this = this;

        callback && callback({"result":0,"spuid":myData.data.uuid});


    }

    __proto.pay = function (param, callback) {
        console.log("玩吧H5支付：" + JSON.stringify(param));
        var m_this = this;
        m_this.paycallback = callback;
        var price = param.data.amount;
        window.popPayTips({defaultScore : price*0.8});
    };
    __proto.sendToDesktop = function (param, callback) {
        console.log("玩吧H5发送桌面：" + JSON.stringify(param));
        var m_this = this;
    }
    __proto.share = function (param, callback) {
        console.log("玩吧H5分享：" + JSON.stringify(param));
        var m_this = this;

        WBExternal.showShareDialog({appid:m_this.appId,title :param.title,summary:param.content,pic:param.imgUrl,
            shareCancel : function (data) {
                callback && callback(JSON.stringify({"result":-1,"desc":"cancel"}));
            },
            shareSuccess : function (data) {
                callback && callback(JSON.stringify({"result":0,"desc":"ok"}));
            },
            shareError : function (data) {
                callback && callback(JSON.stringify({"result":-2,"desc":"error"}));
            }});
    }

    __proto.init = function (param, callback) {
        console.log("玩吧H5初始化：" + JSON.stringify(param));
        var m_this = this;
        m_this.appId = param.appId;
        m_this.appKey = param.appKey;
        m_this.payKey = param.payKey;
        m_this.loginKey = param.loginKey;
        m_this.otherKey = param.other;
        m_this.queryParams = param.queryParams;
        window.__paySuccess = function(){
            m_this.paycallback &&  m_this.paycallback({"result":0,"desc":"success"});
        }
        window.__payError = function(){
            m_this.paycallback &&  m_this.paycallback({"result":-2,"desc":"fail"});
        }
        window.__payClose = function(){
            m_this.paycallback &&  m_this.paycallback({"result":-1,"desc":"cancel"});
        }
        LayaCommon.loadScript(SHARE_URL,function() {
            LayaCommon.loadScript(PAY_URL,function() {
                callback && callback({"result": 0, "desc": "OK"});
            });
        });
    };
    return SPSdk;
})();